<template>
	<div>
		<div v-if="!exportQuestion">
			<div class="topTitle">用户管理</div>
			<el-form :model="query" inline label-width="80px">
				<el-form-item label="模糊搜索">
					<el-input v-model="query.name" placeholder="请输入用户ID、昵称、手机号" class="width260 margin-right10"></el-input>
				</el-form-item>
				<el-form-item label="报考地区">
					<el-cascader :show-all-levels="false" :props="props" v-model="areaData" placeholder="请选择所属地区"
						@change="areaChange" class="margin-right10 width260">
					</el-cascader>
				</el-form-item>
				<el-form-item label="报考类型">
					<el-select v-model="query.targetId" placeholder="请选择报考类型" class="width260 margin-right10">
						<el-option v-for="(item,index) in levelList" :key="index" :label="item.name" :value="item.id"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="注册时间">
					<el-date-picker v-model="dateTime" type="datetimerange" range-separator="至" start-placeholder="开始日期"
						end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss" @change="onDateChange">
					</el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="el-icon-search" class="margin-left10" @click="handleSearch">搜索</el-button>
					<el-button type="default" icon="el-icon-refresh-right" @click="handleRefresh">重置</el-button>
				</el-form-item>
			</el-form>
			<div class="margin-top20 margin-bottom20">
				<el-button type="primary" @click="handleBatchDel">批量删除</el-button>
				<el-button type="primary" @click="handleExport">批量导出</el-button>
				<el-button type="primary" @click="setHeadImgVisible=true">默认头像设置</el-button>
			</div>
			<el-table :data="tableData" border header-cell-class-name="table-header-style"
				@selection-change="handleSelectionChange">
				<el-table-column type="selection" width="55" align="center"></el-table-column>
				<el-table-column prop="id" label="用户ID" align="center"></el-table-column>
				<el-table-column label="头像/昵称" width="160px" align="center">
					<template slot-scope="scope">
						<div class="row-me center-all">
							<el-image class="width50 height50 margin-right10" :src="scope.row.headImage"
								:preview-src-list="[scope.row.headImage]"></el-image>
							<span>{{scope.row.name}}</span>
						</div>
					</template>
				</el-table-column>
				<el-table-column prop="mobile" label="电话" width="120px" align="center"></el-table-column>
				<el-table-column prop="wxAccount" label="微信号"></el-table-column>
				<el-table-column prop="cityName" label="报考地区"></el-table-column>
				<el-table-column prop="answerNum" label="做题总数"></el-table-column>
				<el-table-column prop="createTime" label="注册时间" width="160"></el-table-column>
				<el-table-column label="用户类型" prop="identity"></el-table-column>
				<el-table-column label="报考类型" width="220">
					<template slot-scope="{row}">
						<div v-if="row.tails" class="row-me row-center">
							<span>{{row.tails.target||''}}</span>
							<span v-if="row.tails.target" class="margin-left5 margin-right5">-</span>
							<span>{{row.tails.studyPhase||''}}</span>
							<span v-if="row.tails.studyPhase" class="margin-left5 margin-right5">-</span>
							<span>{{row.tails.subject||''}}</span>
						</div>
					</template>
				</el-table-column>
				<el-table-column label="兑换科目" width="200">
					<template slot-scope="{row}">
						<div v-if="row.activationCodes&&row.activationCodes.length!=0">
							<div v-for="(item,index) in row.activationCodes" :key="index">
								{{item.appName||''}}
								<span v-if="item.validation==1">(长期有效)</span>
								<span v-else-if="item.validation==2">
									{{isExpired(item.endTime||'')?'(已过期)':item.endTime}}
								</span>
							</div>
						</div>
					</template>
				</el-table-column>
				<el-table-column label="上级" width="140" prop="spreadName"></el-table-column>
				<el-table-column prop="coin" width="100px" align="center" label="优惠券数量"></el-table-column>
				<el-table-column prop="balance" label="收益余额" align="center">
					<template slot-scope="{row}">
						<span class="colorBlue pointer" @click="clickBalance(row)">{{row.balance}}</span>
					</template>
				</el-table-column>
				<el-table-column label="是否在线" align="center">
					<template slot-scope="scope">
						<div class="row-me center-all">
							<span :class="['yuan',scope.$index%2?'gray':'green']"></span>
							<div>{{scope.$index%2?'离线':'在线'}}</div>
						</div>
					</template>
				</el-table-column>
				<el-table-column label="操作" width="350" align="center" fixed="right">
					<template slot-scope="scope">
						<el-button type="text" icon="el-icon-mobile" @click="deviceManageBtn(scope.row)">
							设备 </el-button>
						<el-button type="text" icon="el-icon-edit" @click="handleLock(scope.row)">{{scope.row.isLocked?'解封':'封号'}}
						</el-button>
						<el-button type="text" icon="el-icon-edit" @click="handleEdit(scope.row)">编辑
						</el-button>
						<el-button type="text" icon="el-icon-info" @click="handleInfo(scope.row)">详情
						</el-button>
						<el-dropdown>
							<span class="el-dropdown-link">
								更多<i class="el-icon-arrow-down el-icon--right"></i>
							</span>
							<el-dropdown-menu slot="dropdown">
								<el-dropdown-item @click.native="checkErrorTopic(scope.row)">
									<span class="blue-text">查看错题</span>
								</el-dropdown-item>
								<el-dropdown-item @click.native="checkCollectionTopic(scope.row)">
									<span class="blue-text">查看收藏的题</span>
								</el-dropdown-item>
								<el-dropdown-item @click.native="handleDelete(scope.row.id)">
									<span class="blue-text">删除</span>
								</el-dropdown-item>
								<el-dropdown-item @click.native="handleEditUserAgent(scope.row)">
									<span class="blue-text">设置上级</span>
								</el-dropdown-item>
								<el-dropdown-item @click.native="handlePromoter(scope.row)">
									<span class="blue-text">{{scope.row.isPromoter?'取消推广人':'设为推广人'}}</span>
								</el-dropdown-item>
							</el-dropdown-menu>
						</el-dropdown>
					</template>
				</el-table-column>
			</el-table>
			<div class="margin-top10">
				<el-pagination background layout="->,total,sizes, prev, pager, next" :current-page="query.pageNumber"
					:page-sizes="[30, 40, 50, 60]" @size-change="handleSizeChange" :page-size="query.pageSize" :total="pageTotal"
					@current-change="handlePageChange"></el-pagination>
			</div>
		</div>

		<div v-if="exportQuestion" v-loading="exportLoading" element-loading-text="拼命加载中"
			element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)">
			<el-page-header @back="exportQuestion=false" :content="exportType==1?'错题结果集':'收藏题结果集'"
				style="margin-bottom: 30px;">
			</el-page-header>
			<el-button @click="selectAll" class="margin-bottom20">复制全部</el-button>
			<div id="aaa">
				<el-card class="box-card" style="margin-bottom: 10px;" v-for="(question, index) in exportQuestionList"
					:key="index">
					<b>
						<p
							v-html="(index + 1 + '.' + (question.tails.title?question.tails.title:question.title) + (question.abbreviation == null ? '' : question.abbreviation))">
						</p>
					</b>
					<div v-if="question.type.value == 0 || question.type.value == 1">
						<p v-for="(item, index) in question.optionList">{{ optionNoArr[index] }}. {{ item.content }}
						</p>
					</div>
					<b>
						<p style="color:red">答案：<span v-html="question.answer"></span></p>
					</b>
					<b>
						<p>解析：<span v-html="question.textExplain"></span></p>
					</b>
				</el-card>
			</div>
		</div>

		<!-- 用户设备弹出框 -->
		<el-dialog :visible.sync="deviceVisible">
			<el-table :data="deviceData" border class="table" ref="multipleTable" header-cell-class-name="table-header-style">
				<el-table-column prop="type" label="设备类型"></el-table-column>
				<el-table-column prop="model" label="设备型号"></el-table-column>
				<el-table-column prop="deviceName" label="设备名"></el-table-column>
				<el-table-column prop="imei" label="imei"></el-table-column>
				<el-table-column prop="createTime" label="创建时间"></el-table-column>
				<el-table-column label="操作" width="180" align="center">
					<template slot-scope="scope">
						<el-button type="text" icon="el-icon-delete" @click="delDevice(scope.row.id)">删除
						</el-button>
					</template>
				</el-table-column>
			</el-table>
		</el-dialog>

		<!-- 编辑弹出框 -->
		<el-dialog title="编辑" :visible.sync="editVisible" width="600px">
			<el-form ref="form" :model="form" label-width="100px">
				<el-form-item label="手机号">
					<el-input class="width300" v-model="form.mobile" placeholder="不填写即不修改手机号"></el-input>
				</el-form-item>
				<el-form-item label="微信号">
					<el-input class="width300" v-model="form.wxAccount" placeholder="不填写即不修改微信号"></el-input>
				</el-form-item>
				<el-form-item label="昵称">
					<el-input class="width300" v-model="form.name" placeholder="不填写即不修改昵称"></el-input>
				</el-form-item>
				<el-form-item label="密码">
					<el-input class="width300" v-model="form.password" placeholder="不填写即不修改密码"></el-input>
				</el-form-item>
				<el-form-item label="地区">
					<el-cascader :props="props" v-model="form.cityName" :placeholder="form.cityName" name="cascader"
						popper-class="cascader"></el-cascader>
				</el-form-item>
				<el-form-item label="代理推广收益">
					<el-input class="width300" v-model="form.agentReward" placeholder="请输入代理推广收益"></el-input>
				</el-form-item>
				<el-form-item label="代理直推收益">
					<el-input class="width300" v-model="form.agentDirectReward" placeholder="请输入代理直推收益"></el-input>
				</el-form-item>
				<el-form-item label="备注">
					<el-input class="width300" v-model="form.remark" placeholder="备注"></el-input>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="editVisible = false">取 消</el-button>
				<el-button type="primary" @click="saveEdit">确 定</el-button>
			</span>
		</el-dialog>

		<!-- 用户订单弹出框 -->
		<el-dialog :visible.sync="detailVisible" width="60%">
			<div class="row-me flex-end">
				<span>推广收益：{{userRewardInfo.data||0}}元</span>
			</div>
			<el-tabs v-model="activeName" @tab-click="onTabsChange">
				<el-tab-pane label="商品订单" name="first"></el-tab-pane>
				<el-tab-pane label="专题订单" name="second"></el-tab-pane>
			</el-tabs>
			<el-table :data="detailData" border class="table" ref="multipleTable" header-cell-class-name="table-header">
				<el-table-column type="index" label="序号" align="center"></el-table-column>
				<el-table-column prop="orderNo" label="订单编号"></el-table-column>
				<el-table-column prop="addressName" label="收件人"></el-table-column>
				<el-table-column prop="addressPhoneNumber" label="联系方式"></el-table-column>
				<el-table-column prop="addressDetailAddress" label="收货地址"></el-table-column>
				<el-table-column prop="createTime" label="下单时间"></el-table-column>
				<el-table-column label="支付方式">
					<template slot-scope="scope">
						<span>{{scope.row.payType==1?'支付宝':scope.row.payType==2?'微信':''}}</span>
					</template>
				</el-table-column>
				<el-table-column property="title" label="商品信息" align="center" width="500">
					<template slot-scope="scope">
						<div class="row-me row-center">
							<img v-if="scope.row.picture" :src="scope.row.picture" alt="" class="width50 height50 margin-right10">
							<span>{{scope.row.title||''}}</span>
						</div>
					</template>
				</el-table-column>
				<el-table-column prop="totalAmount" label="商品价格"></el-table-column>
				<el-table-column prop="payAmount" label="实付金额">
					<template slot-scope="scope">
						<el-tag type="info">{{scope.row.payAmount}}</el-tag>
					</template>
				</el-table-column>
				<el-table-column prop="totalAmount" label="订单属性"></el-table-column>
				<el-table-column prop="totalAmount" label="推广提成"></el-table-column>
				<el-table-column label="订单状态" align="center">
					<template slot-scope="scope">
						<span v-if="scope.row.status==1">待支付</span>
						<span v-else-if="scope.row.status==2">待发货</span>
						<span v-else-if="scope.row.status==3">待收货</span>
						<span v-else-if="scope.row.status==4">已完成</span>
						<span v-else-if="scope.row.status==5">退款中</span>
						<span v-else-if="scope.row.status==6">已退款</span>
						<span v-else-if="scope.row.status==7">已失效</span>
						<span v-else-if="scope.row.status==8">待评价</span>
						<span v-else-if="scope.row.status==-1">已取消</span>
					</template>
				</el-table-column>
				<el-table-column prop="itemName" label="发货单号"></el-table-column>
			</el-table>
			<div class="pagination">
				<el-pagination background layout="total,sizes, prev, pager, next" :page-sizes="[30, 40, 50, 60]"
					@size-change="handleDetailSizeChange" :current-page="detailParams.pageNumber" :total="detailTotal"
					@current-change="handleDetailPageChange"></el-pagination>
			</div>
			<span slot="footer" class="dialog-footer">
				<el-button type="primary" @click="detailVisible = false">关 闭</el-button>
			</span>
		</el-dialog>

		<!-- 用户错题 -->
		<el-dialog title="用户错题" :visible.sync="wrongQuestionVisible" width="60%">
			<div class="row-me flex-end margin-bottom20">
				<el-button type="primary" @click="clickExport(1)">导出</el-button>
			</div>
			<el-table :data="wrongTopicData" border class="table" header-cell-class-name="table-header">
				<el-table-column label="用户头像" prop="avatar" align="center" width="200">
					<template slot-scope="scope">
						<div class="row-me center-all">
							<el-image class="width50 width50 radius6 margin-right10" :src="collectionUser.headImage"
								:preview-src-list="[collectionUser.headImage]"></el-image>
							<span>{{collectionUser.name}}</span>
						</div>
					</template>
				</el-table-column>
				<el-table-column label="题目ID" prop="id" align="center" width="100"></el-table-column>
				<el-table-column label="题目内容" prop="tails.title" align="center"></el-table-column>
				<el-table-column label="正确率" prop="tails.accurate" align="center" width="100"></el-table-column>
			</el-table>
			<div class="pagination">
				<el-pagination background layout="total,sizes, prev, pager, next" :page-sizes="[30, 40, 50, 60]"
					@size-change="handleWrongSizeChange" :current-page="wrongTopicParams.pageNumber" :total="wrongTopicTotal"
					@current-change="handleWrongPageChange"></el-pagination>
			</div>
			<span slot="footer" class="dialog-footer">
				<el-button type="primary" @click="wrongQuestionVisible = false">关 闭</el-button>
			</span>
		</el-dialog>

		<!-- 用户收藏题 -->
		<el-dialog title="用户收藏题" :visible.sync="collectionTopicVisible" width="60%">
			<div class="row-me flex-end margin-bottom20">
				<el-button type="primary" @click="clickExport(2)">导出</el-button>
			</div>
			<el-table :data="collectionTopicData" border class="table" header-cell-class-name="table-header">
				<el-table-column label="用户头像/昵称" prop="avatar" align="center" width="200">
					<template slot-scope="scope">
						<div class="row-me center-all">
							<el-image class="table-td-thumb mr10" :src="collectionUser.headImage"
								:preview-src-list="[collectionUser.headImage]"></el-image>
							<span>{{collectionUser.name}}</span>
						</div>
					</template>
				</el-table-column>
				<el-table-column label="题目ID" prop="id" align="center" width="100"></el-table-column>
				<el-table-column label="题目内容" prop="title" align="center"></el-table-column>
				<el-table-column label="题型" prop="type.name" align="center" width="100"></el-table-column>
			</el-table>
			<div class="pagination">
				<el-pagination background layout="total,sizes, prev, pager, next" :page-sizes="[30, 40, 50, 60]"
					@size-change="handleCollectionSizeChange" :current-page="collectionTopicParams.pageNumber"
					:total="collectionTopicTotal" @current-change="handleCollectionPageChange"></el-pagination>
			</div>
			<span slot="footer" class="dialog-footer">
				<el-button type="primary" @click="collectionTopicVisible = false">关 闭</el-button>
			</span>
		</el-dialog>

		<!-- 代理编辑弹出框 -->
		<el-dialog title="设置上级代理" :visible.sync="editUserAgentVisible" width="25%">
			<el-form ref="form" :model="form" label-width="100px">
				<el-form-item label="上级代理">
					<template>
						<el-select v-model="form.spreadId" clearable filterable default-first-option placeholder="请选择上级代理">
							<el-option v-for="item in agentDatas" :key="item.id" :label="item.mobile" :value="item.id">
							</el-option>
						</el-select>
					</template>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="editUserAgentVisible = false">取 消</el-button>
				<el-button type="primary" @click="saveEditUserAgent">确 定</el-button>
			</span>
		</el-dialog>

		<!-- 头像设置 -->
		<el-dialog title="默认头像设置" :visible.sync="setHeadImgVisible" width="40%">
			<el-form :model="setHeadImgForm">
				<el-form-item label="上传默认头像">
					<el-image v-if="setHeadImgForm.value" class="width100 height100 radius6 margin-right10"
						:src="setHeadImgForm.value" :preview-src-list="[setHeadImgForm.value]"></el-image>
					<el-button type="text" @click="clickImg">点击图片库</el-button>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="setHeadImgVisible = false">取 消</el-button>
				<el-button @click="setHeadImgSave" type="primary">确 认</el-button>
			</span>
		</el-dialog>

		<!-- 收益明细 -->
		<el-dialog title="收益明细" :visible.sync="balanceVisible" width="60%">
			<el-tabs v-model="activeName2" @tab-click="handleClick">
				<el-tab-pane label="收支明细" name="first">
					<el-table :data="balanceTable" border class="table" ref="multipleTable" header-cell-class-name="table-header">
						<el-table-column type="index" label="序号" align="center"></el-table-column>
						<el-table-column label="下单用户ID/昵称">
							<template slot-scope="{row}">
								<div class="row-me row-center">
									<span>{{row.userId}}</span>
									<span>{{row.userName}}</span>
								</div>
							</template>
						</el-table-column>
						<el-table-column label="收支类型">
							<template slot-scope="{row}">
								<span v-if="row.changeType==1">提现</span>
								<span v-else-if="row.changeType==2">收入</span>
							</template>
						</el-table-column>
						<el-table-column prop="money" label="金额"></el-table-column>
						<el-table-column prop="afterBalances" label="余额"></el-table-column>
						<el-table-column prop="createTime" label="创建时间"></el-table-column>
					</el-table>
				</el-tab-pane>
				<el-tab-pane label="结算明细" name="second">
					<el-table :data="balanceTable" border class="table" ref="multipleTable" header-cell-class-name="table-header">
						<el-table-column type="index" label="序号" align="center"></el-table-column>
						<el-table-column label="下单用户ID/昵称">
							<template slot-scope="{row}">
								<div class="row-me row-center">
									<span>{{row.userId}}</span>
									<span>{{row.userName}}</span>
								</div>
							</template>
						</el-table-column>
						<el-table-column label="类型">
							<template slot-scope="{row}">
								<span v-if="row.orderType==1">商城</span>
								<span v-else-if="row.type==2">专题</span>
							</template>
						</el-table-column>
						<el-table-column prop="title" label="商品/专题名称"></el-table-column>
						<el-table-column prop="payAmount" label="支付金额"></el-table-column>
						<el-table-column prop="reward" label="收益金额"></el-table-column>
						<el-table-column label="状态">
							<template slot-scope="{row}">
								<span v-if="row.status==1">待结算</span>
								<span v-else-if="row.status==2">已结算</span>
								<span v-else-if="row.status==3">已退款</span>
							</template>
						</el-table-column>
						<el-table-column prop="createTime" label="交易时间"></el-table-column>
					</el-table>
				</el-tab-pane>
				<div class="pagination">
					<el-pagination background layout="total,sizes, prev, pager, next" :page-sizes="[30, 40, 50, 60]"
						@size-change="handleBalanceSizeChange" :current-page="balanceParams.pageNumber" :total="balanceTotal"
						@current-change="handleBalancePageChange"></el-pagination>
				</div>
			</el-tabs>
			<span slot="footer" class="dialog-footer">
				<el-button @click="balanceVisible = false" type="primary">关 闭</el-button>
			</span>
		</el-dialog>


		<imgLibrary ref="imgLibrary" @handleImgOk="handleImgOk"></imgLibrary>
	</div>
</template>

<script>
	import imgLibrary from "@/components/imgLibrary"
	export default {
		components: {
			imgLibrary
		},
		data() {
			return {
				query: {
					pageNumber: 1,
					pageSize: 30
				},
				pageTotal: 0,
				tableData: [],
				multipleSelection: [],
				props: {
					emitPath: false,
					lazy: true,
					lazyLoad: this.lazyLoad,
					checkStrictly: true,
				},
				areaData: [],
				dateTime: [],
				deviceData: [],
				deviceVisible: false,
				deviceQuery: {},
				form: {},
				editVisible: false,
				detailVisible: false,
				userDetailId: '',
				detailParams: {
					pageNumber: 1,
					pageSize: 30,
				},
				detailTotal: 0,
				userRewardInfo: {},
				wrongTopicParams: {
					pageNumber: 1,
					pageSize: 30
				},
				wrongTopicData: [],
				wrongTopicTotal: 0,
				collectionUser: {},
				wrongQuestionVisible: false,
				collectionTopicVisible: false,
				exportLoading: true,
				exportQuestion: false,
				exportType: 1,
				exportQuestionList: [],
				collectionTopicParams: {
					pageNumber: 1,
					pageSize: 30
				},
				collectionTopicTotal: 0,
				collectionTopicData: [],
				editUserAgentVisible: false,
				agentDatas: [],
				setHeadImgVisible: false,
				setHeadImgForm: {},
				fileList: [],
				activeName: 'first',
				detailData: [],
				levelList: [],
				balanceInfo: {},
				balanceVisible: false,
				activeName2: 'first',
				balanceTable: [],
				balanceParams: {
					pageNumber: 1,
					pageSize: 30
				},
				balanceIndex: 0,
				balanceTotal: 0
			}
		},
		mounted() {
			this.getAgentData()
			this.getData()
			this.getByKey()
			this.getLevelList()
		},
		methods: {
			handleClick({
				index
			}) {
				this.balanceIndex = index
				console.log(index, "index")
				let url = '/admin/user/pageMoneyChange'
				if (index == 1) {
					url = '/admin/user/getRewardDetail'
				}
				this.$get(url, this.balanceParams).then(res => {
					if (res.code == 1000) {
						this.balanceTable = res.data.list
						this.balanceTotal = res.data.totalRow
					}
				})
			},
			isExpired(date) {
				const currentDate = new Date();
				return currentDate > date;
			},
			async getLevelList() {
				const res = await this.$get('/admin/studyGuide/listLevel1')
				if (res.code == 1000) {
					this.levelList = res.data
				}
			},
			//获取选中的图片
			handleImgOk(data) {
				this.$set(this.setHeadImgForm, 'value', data)
			},
			//点击图片库
			clickImg() {
				this.$refs.imgLibrary.show()
			},
			async setHeadImgSave() {
				if (this.setHeadImgForm.type && this.setHeadImgForm.type.value) {
					this.setHeadImgForm.type = this.setHeadImgForm.type.value
				}
				const res = await this.$post('/admin/config/update', this.setHeadImgForm)
				if (res.code == 1000) {
					this.$message.success('设置成功')
					this.setHeadImgVisible = false
					this.getByKey()
				}
			},
			//获取默认头像
			async getByKey() {
				const res = await this.$get('/admin/config/getByKey', {
					key: 'config_default_headImage'
				})
				this.setHeadImgForm = res.data
				if (this.setHeadImgForm.type.value == 3) {
					this.fileList = [{
						url: this.setHeadImgForm.value
					}]
				}
			},
			//批量导出
			handleExport() {
				this.query.pageNumber = 1
				let params = this.query
				if (typeof params.cityName == 'number') {
					params.cityName = "";
				}
				if (params.cityName != '' && params.cityName != null) {
					if (this.query.cityName.indexOf('_') >= 0) params.cityName = params.cityName.split('_')[1];
				}
				params.pageSize = 1000000000;
				params.appid = localStorage.getItem('appid');
				params.token = localStorage.getItem('token');
				window.open(this.$host + '/admin/user/export?' + this.$.getParamsString(params));
			},
			// 设置上级代理
			async saveEditUserAgent() {
				const res = await this.$post('/admin/user/changeAgent', this.form)
				if (res.code == 1000) {
					this.$message.success('设置成功')
					this.getData()
					this.editUserAgentVisible = false
					this.form = {}
				}
			},
			//获取代理下拉
			async getAgentData() {
				const res = await this.$get('/admin/user/getAllAgent')
				if (res.code == 1000) {
					this.agentDatas = res.data
				}
			},
			// 修改用户的上级
			handleEditUserAgent(row) {
				this.editUserAgentVisible = true;
				this.form.id = row.id;
				this.form.spreadId = row.spreadId;
			},
			//设为推广人
			async handlePromoter(item) {
				const res = await this.$postForm('/admin/user/userPromoterUpdate', {
					id: item.id,
					isPromoter: item.isPromoter ? false : true
				})
				if (res.code == 1000) {
					this.$message.success('操作成功')
					this.getData()
				}
			},
			// 删除操作
			handleDelete(id) {
				this.$confirm('确定要删除吗？', '提示', {
						type: 'warning'
					})
					.then(() => {
						this.$get('/admin/user/delete', {
							id
						}).then(res => {
							this.$message.success('删除成功');
							this.getData();
						})
					})
					.catch(() => {});
			},
			//收藏分页
			handleCollectionSizeChange(val) {
				this.collectionTopicParams.pageSize = val
				this.getPageFavorite()
			},
			handleCollectionPageChange(val) {
				this.collectionTopicParams.pageNumber = val
				this.getPageFavorite()
			},
			//查看收藏题
			async checkCollectionTopic(row) {
				this.collectionTopicParams.userId = row.id
				this.collectionUser = row
				this.collectionTopicVisible = true
				this.getPageFavorite()
			},
			//获取收藏数据
			async getPageFavorite() {
				const res = await this.$get('/admin/user/pageFavorite', this.collectionTopicParams)
				if (res.code == 1000) {
					this.collectionTopicData = res.data.list
					this.collectionTopicTotal = res.data.totalRow
				}
			},
			//复制全部
			selectAll() {
				// 获取selection对象
				var selection = window.getSelection();
				// 清空selection对象
				selection.removeAllRanges();
				// 创建一个Range实例
				var ele = document.getElementById('aaa');
				var range = new Range();
				range.selectNodeContents(ele);
				// selection对象设置range实例
				selection.addRange(range);
				document.execCommand('Copy');
				this.$message.success('已复制到粘贴板');
			},
			// 导出
			async clickExport(type) {
				this.exportType = type
				if (type == 1) {
					this.wrongTopicParams.pageSize = 1000000
					const res = await this.$get('/admin/user/pageIncorrect', this.wrongTopicParams)
					this.exportQuestionList = res.data.list
					this.wrongQuestionVisible = false
				} else {
					this.collectionTopicParams.pageSize = 1000000
					const res2 = await this.$get('/admin/user/pageFavorite', this.collectionTopicParams)
					this.exportQuestionList = res2.data.list
					this.collectionTopicVisible = false
				}
				this.exportLoading = false
				this.exportQuestion = true
			},
			//错题分页
			handleWrongSizeChange(val) {
				this.wrongTopicParams.pageSize = val
				this.getPageIncorrect()
			},
			handleWrongPageChange(val) {
				this.balanceParams.pageNumber = val
				this.getPageIncorrect()
			},
			//收益明细分页
			handleBalanceSizeChange(val) {
				this.balanceParams.pageSize = val
				this.handleClick(this.balanceIndex)
			},
			handleBalancePageChange(val) {
				this.wrongTopicParams.pageNumber = val
				this.handleClick(this.balanceIndex)
			},
			//查看错题
			async checkErrorTopic(row) {
				this.wrongTopicParams.userId = row.id
				this.collectionUser = row
				this.getPageIncorrect()
				this.wrongQuestionVisible = true
			},
			async getPageIncorrect() {
				const res = await this.$get('/admin/user/pageIncorrect', this.wrongTopicParams)
				if (res.code == 1000) {
					this.wrongTopicData = res.data.list
					this.wrongTopicTotal = res.data.totalRow
				}
			},
			//详情分页
			handleDetailSizeChange(val) {
				this.detailParams.pageSize = val
				this.onTabsChange({
					index: 0
				})
			},
			handleDetailPageChange(val) {
				this.detailParams.pageNumber = val
				this.onTabsChange({
					index: 0
				})
			},
			async getUserReward(row) {
				const res = await this.$get('/admin/user/getUserReward', {
					userId: row.id
				})
				if (res.code == 1000) {
					this.userRewardInfo.data = res.data
					this.userRewardInfo.data1 = res.data1
				}
			},
			//收益明细
			clickBalance(row) {
				this.balanceParams.userId = row.id
				this.balanceVisible = true
				this.handleClick(0)
			},
			//详情
			handleInfo(row) {
				this.getUserReward(row)
				this.onTabsChange({
					index: 0
				})
				this.detailParams.userId = row.id
				this.detailVisible = true;
			},
			async onTabsChange(tab) {
				this.detailParams.type = tab.index + 1
				const res = await this.$get('/admin/order/pageQueryMallOrder', this.detailParams)
				if (res.code == 1000) {
					this.detailData = res.data.list
					this.detailTotal = res.data.totalRow
				}
			},
			//保存编辑
			async saveEdit() {
				const res = await this.$post('/admin/user/insertUser', this.form)
				if (res.code == 1000) {
					this.$message.success('编辑成功')
					this.editVisible = false
					this.getData()
				}
			},
			// 编辑操作
			handleEdit(row) {
				this.form = JSON.parse(JSON.stringify(row))
				this.editVisible = true;
			},
			// 封号 解封操作
			handleLock(row) {
				this.$confirm('确定要将【' + row.name + '】进行' + (rwo.isLocked ? '解封' : '封号') + '吗？', '提示', {
						type: 'warning'
					})
					.then(() => {
						let type = row.isLocked ? 0 : 1
						this.$get('/admin/user/lock', {
							id: row.id,
							type
						}).then(res => {
							if (res.code == 1000) {
								this.$message.success('操作成功');
								this.getData();
							}
						})
					})
					.catch(() => {});
			},
			//删除用户设备
			async delDevice(id) {
				const res = await this.$get('/admin/user/delDevice', {
					id
				})
				if (res.code == 1000) {
					this.$message.success('删除成功');
					this.deviceVisible = false;
					this.getDeviceData()
				}
			},
			//设备
			deviceManageBtn(row) {
				this.deviceQuery.id = row.id
				this.deviceVisible = true
				this.getDeviceData()
			},
			//获取设备数据
			async getDeviceData() {
				const res = await this.$get('/admin/user/getDeviceList', {
					id: this.deviceQuery.id
				})
				if (res.code == 1000) {
					this.deviceData = res.data
				}
			},
			//分页
			handlePageChange(val) {
				this.query.pageNumber = val
				this.getData();
			},
			handleSizeChange(val) {
				this.query.pageSize = val
				this.getData();
			},
			//获取数据
			async getData() {
				const res = await this.$get('/admin/user/page', this.query)
				if (res.code == 1000) {
					this.tableData = res.data.list
					this.pageTotal = res.data.totalRow
				}
			},
			//多选操作
			handleSelectionChange(val) {
				this.multipleSelection = val
			},
			//批量删除
			handleBatchDel() {
				this.$confirm('确定要批量删除已选中的题目吗？', '提示', {
					type: 'warning'
				}).then(() => {
					if (this.multipleSelection.length == 0) return
					let ids = Array.from(this.multipleSelection, ({
						id
					}) => id)
					this.$postForm('/admin/label/labelDelete', {
						ids
					}).then(res => {
						if (res.code == 1000) {
							this.$message.success('批量删除成功')
							this.getData()
							this.multipleSelection = []
						}
					})
				}).catch(() => {})
			},
			//搜索
			handleSearch() {
				this.query.pageNumber = 1
				this.getData();
			},
			//重置
			handleRefresh() {
				this.query = {
					pageNumber: 1,
					pageSize: 30
				}
				this.dateTime = []
				this.getData();
			},
			//注册时间变动
			onDateChange(val) {
				if (val.length == 0) {
					this.query.startTime = ''
					this.query.endTime = ''
				} else {
					this.query.startTime = val[0]
					this.query.endTime = val[1]
				}
			},
			//报考地区变动
			areaChange(val) {
				if (!this.$.isEmpty(val)) {
					let area = val.split('_')
					if (area[1] == 0) {
						this.query.province = area[2]
					} else {
						this.query.city = area[2]
					}
				}
			},
			getProvince() {
				var vm = this;
				return new Promise(function(resolve) {
					vm.$get('/admin/area/getProvince')
						.then(function(response) {
							response.data.unshift({
								name: '默认',
								id: '0'
							});
							vm.citys = response.data;
							resolve();
						});
				});
			},
			getCity(val) {
				var vm = this;
				return new Promise(function(resolve) {
					if (val == undefined || val == '0') {
						resolve([{
							name: '默认',
							id: ''
						}]);
					} else {
						vm.$get('/admin/area/getCities', {
								provinceId: val,
							})
							.then(function(response) {
								resolve(response.data);
							});
					}
				});
			},
			//加载省市选择项
			lazyLoad(node, resolve) {
				let vm = this;
				if (node.level == 0) {
					this.getProvince(node.value).then(() => {
						const nodes = vm.citys.map(item => ({
							value: item.id + '_' + '0_' + item.name,
							label: item.name,
							leaf: node.level >= 2
						}));
						resolve(nodes);
					});
				} else {
					this.getCity(node.value.split('_')[0]).then(city => {
						const nodes = city.map(item => ({
							value: item.id + '_' + '1_' + item.name,
							label: item.name,
							leaf: node.level >= 2
						}));
						resolve(nodes);
					});
				}
			},
		}
	}
</script>